package com.jinduplan.planmanager.mvp.presenter

import com.cxz.kotlin.baselibs.ext.ss
import com.cxz.kotlin.baselibs.mvp.BasePresenter
import com.fphoenixcorneae.util.toast.ToastUtil
import com.jinduplan.planmanager.bean.MessageBean
import com.jinduplan.planmanager.mvp.contract.MessageContract
import com.jinduplan.planmanager.mvp.contract.ProjectContract
import com.jinduplan.planmanager.mvp.model.MessageModel
import com.jinduplan.planmanager.mvp.model.ProjectModel

/**
 * @author admin
 * @date 2018/11/20
 * @desc
 */
class MessagePresenter : BasePresenter<MessageContract.Model, MessageContract.View>(),
    MessageContract.Presenter {

    override fun createModel(): MessageContract.Model? = MessageModel()


    override fun getMsgList(page: Int, limit: Int) {
        mModel?.getMsgList(page, limit)?.ss(mModel, mView, page == 1, onSuccess = {
            if (it.code == 200) {
                mView?.setMsgListData(it.data!!)
            }
        }, onError = {
            ToastUtil.show(it.msg)
        })
    }

    override fun readMessage(id: Int, is_read: Int) {
        mModel?.readMessage(id, is_read)?.ss(mModel, mView, true, onSuccess = {
            if (it.code == 200) {
                mView?.readMsgSuccess()
            }
        }, onError = {
            ToastUtil.show(it.msg)
        })
    }

    override fun getProjectList(page: Int, limit: Int,project_id:Int,audit_id:Int,msg: MessageBean.DataBean) {
        mModel?.getProjectList(page, limit,project_id,audit_id)?.ss(mModel, mView, page == 1, onSuccess = {
            if (it.code == 200) {
                mView?.setProjectListData(it.data!!,msg)
            }
        }, onError = {
            ToastUtil.show(it.msg)
        })

    }


}